package com.zhida.smartcontrol.pagectrl.projectdetail.zonemanager;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.recycler.MultipleViewHolder;
import com.jay.tools.recycler.OnItemClick;
import com.jay.tools.recycler.SingleRecyclerAdapter;
import com.jay.tools.utils.DimenUtils;
import com.jay.tools.utils.ResUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.pagectrl.projectdetail.GroupBean;
import com.zhida.smartcontrol.pop.GroupPop;

import java.util.List;

public class QuduanAdapter extends SingleRecyclerAdapter<GroupBean> {
    private int mColor6;
    private int mColor9;

    private GroupPop mPop;
    private int mX, mY;

    public QuduanAdapter(@Nullable List<GroupBean> data) {
        super(R.layout.item_quduan, data);
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        Context context = recyclerView.getContext();
        mPop = new GroupPop(context);
        mColor6 = ResUtil.getColor(context, R.color.c_666666);
        mColor9 = ResUtil.getColor(context, R.color.c_999999);
        mX = DimenUtils.dp2px(context, 60);
        mY = -DimenUtils.dp2px(context, 20);
    }

    @Override
    protected void convert(MultipleViewHolder holder, GroupBean info) {
        TextView mTv = holder.getView(R.id.tv_item);

        mTv.setText(info.getName());

        if (mPosition == holder.getAdapterPosition()) {
            mTv.setTextColor(mColor6);
            mTv.setBackgroundResource(R.color.c_FAFAFA);
        } else {
            mTv.setTextColor(mColor9);
            mTv.setBackgroundResource(R.color.c_FFFFFF);
        }

        mTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setPosition(holder.getAdapterPosition());
                if (null != mListener) {
                    mListener.onClick(info, 3);
                }
            }
        });

        mTv.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (null != mListener) {
                    mPop.showAsDropDown(mTv, mX, mY);
                    mPop.setClickListener(new OnItemClick<Object>() {
                        @Override
                        public void onClick(Object bean, int tag) {
                            mListener.onClick(info, tag);
                        }
                    });
                }
                return false;
            }
        });


    }


}
